#delimit ;
clear all;
set more 1;
set maxvar 32000;
version 12;
local seed = 735;

*******************************************************************************;
*directories;
*******************************************************************************;
global upper_dir = "";

global scratch_dir = "$upper_dir\scratch";

global paper_dir = "$upper_dir\tables_figures";

global nlsy_data_dir = "$upper_dir\data";

global dofile_dir = "$upper_dir\stata_code";

*******************************************************************************;
*******************************************************************************;
*Table of Estimates;
*******************************************************************************;
*******************************************************************************;



*upload estimated parameters;
cd "$scratch_dir";
use boot_collect_ols0_restricted0_new.dta , clear;

sort boot_sample;

************************************;
************************************;
*Initial Variance-Covariance Table;
************************************;
************************************;



matrix V = ( var_child_cog[1]            ,   cov_child_cog_mom_cog[1]  ,  cov_child_cog_mom_noncog[1] ,  cov_child_cog_log_inc[1] \
			 cov_child_cog_mom_cog[1]    ,   var_mom_cog[1]            ,  cov_mom_cog_mom_noncog[1]   ,  cov_mom_cog_log_inc[1] \  
			 cov_child_cog_mom_noncog[1] ,	 cov_mom_cog_mom_noncog[1] ,  var_mom_noncog[1]           ,  cov_mom_noncog_log_inc[1] \  
             cov_child_cog_log_inc[1]    ,   cov_mom_cog_log_inc[1]    ,  cov_mom_noncog_log_inc[1]   ,  var_faminc5[1]   );
			 

matrix C = ( 1           ,   corr_child_cog_mom_cog[1]  ,  corr_child_cog_mom_noncog[1] ,  corr_child_cog_log_inc[1] \
			 corr_child_cog_mom_cog[1]    ,   1            ,  corr_mom_cog_mom_noncog[1]   ,  corr_mom_cog_log_inc[1] \  
			 corr_child_cog_mom_noncog[1] ,	 corr_mom_cog_mom_noncog[1] ,  1           ,  corr_mom_noncog_log_inc[1] \  
             corr_child_cog_log_inc[1]    ,   corr_mom_cog_log_inc[1]    ,  corr_mom_noncog_log_inc[1]   ,  1   );			 
			 
			 
*Create the Standard Error of the Estimated Initial Conditions;

local list_V = "var_child_cog                cov_child_cog_mom_cog     cov_child_cog_mom_noncog    cov_child_cog_log_inc  
			 cov_child_cog_mom_cog        var_mom_cog               cov_mom_cog_mom_noncog      cov_mom_cog_log_inc    
			 cov_child_cog_mom_noncog  	 cov_mom_cog_mom_noncog    var_mom_noncog              cov_mom_noncog_log_inc    
             cov_child_cog_log_inc        cov_mom_cog_log_inc       cov_mom_noncog_log_inc      var_faminc5    ";

			 
gen diag = 1 ;			 
			 
local list_C = "       diag          corr_child_cog_mom_cog     corr_child_cog_mom_noncog    corr_child_cog_log_inc 
 corr_child_cog_mom_cog         diag               corr_mom_cog_mom_noncog      corr_mom_cog_log_inc    
corr_child_cog_mom_noncog  	 corr_mom_cog_mom_noncog         diag          corr_mom_noncog_log_inc    
corr_child_cog_log_inc        corr_mom_cog_log_inc       corr_mom_noncog_log_inc       diag    ";
			 
matrix V_se = J(4,4,.) ;
matrix C_se = J(4,4,.) ;

			 
local ind_var = 1;			 
foreach var in `list_V'{;
sum `var';
matrix V_se[ floor(1+(`ind_var'-1)/4) ,  `ind_var'-4*(floor(1+(`ind_var'-1)/4)-1) ]= r(sd);
local ind_var = `ind_var' + 1;
};			 
			 
			 
local ind_var = 1;			 
foreach var in `list_C'{;
sum `var';
matrix C_se[ floor(1+(`ind_var'-1)/4) ,  `ind_var'-4*(floor(1+(`ind_var'-1)/4)-1) ]= r(sd);
local ind_var = `ind_var' + 1;
};			 
			 
file open resultsfile using "$paper_dir\cov_initial_cond.tex", write replace;
file write resultsfile "\begin{tabular}{lcccc}" _n;
file write resultsfile "\hline \hline" _n;
file write resultsfile "\\[0.2cm]" _n;
file write resultsfile "    & \shortstack{ Log Child Skills \\ at age 5} & \shortstack{ Log Mother \\ Cognitive Skills} & \shortstack{ Log Mother \\ Noncognitive Skills} & \shortstack{ Log Family \\ Income} \\" _n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;
file write resultsfile "\multicolumn{5}{c}{Variance-Covariance Matrix} \\"_n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;

forvalues i = 1(1)4{;
  

forvalues j = 1(1)4{; 
local column`j':  di %6.3f V[`i',`j'] ;
local column`j'_se: di %4.3f V_se[`i',`j'] ;
};




if `i'==1{;
file write resultsfile "   Log Child Skills              & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "       at age 5    & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\[0.3cm]" _n;
};

if `i'==2{;
file write resultsfile "  Log Mother    & `column1' & `column2' & `column3' & `column4'  \\ " _n;
file write resultsfile "  Cognitive Skills   & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\[0.3cm]" _n;

};


if `i'==3{;
file write resultsfile "  Log Mother   & `column1' & `column2' & `column3' & `column4'  \\ " _n;
file write resultsfile "  Noncognitive Skills   & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\[0.3cm]" _n;

};

if `i'==4{;
file write resultsfile "  Log Family  & `column1' & `column2' & `column3' & `column4'  \\ " _n;
file write resultsfile "  Income  & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\[0.3cm]" _n;

};

  
};

file write resultsfile "\\[0.2cm]" _n;
file write resultsfile "\multicolumn{5}{c}{Correlation Matrix} \\"_n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;

forvalues i = 1(1)4{;
  

forvalues j = 1(1)4{; 
local column`j':  di %6.3f C[`i',`j'] ;
local column`j'_se: di %4.3f C_se[`i',`j'] ;
};



if `i'==1{;
file write resultsfile "   Log Child Skills              & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "       at age 5    & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\[0.3cm]" _n;
};

if `i'==2{;
file write resultsfile "  Log Mother    & `column1' & `column2' & `column3' & `column4'  \\ " _n;
file write resultsfile "  Cognitive Skills   & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\[0.3cm]" _n;

};


if `i'==3{;
file write resultsfile "  Log Mother   & `column1' & `column2' & `column3' & `column4'  \\ " _n;
file write resultsfile "  Noncognitive Skills   & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\[0.3cm]" _n;

};

if `i'==4{;
file write resultsfile "  Log Family  & `column1' & `column2' & `column3' & `column4'  \\ " _n;
file write resultsfile "  Income  & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\[0.3cm]" _n;

};

  
};

file write resultsfile "\hline \hline" _n;
file write resultsfile "\end{tabular}";
file close resultsfile;


************************************;
************************************;
*Investment Equation ;
************************************;
************************************;
file open resultsfile using "$paper_dir\est_inv.tex", write replace;
file write resultsfile "\begin{tabular}{lcccc}" _n;
file write resultsfile "\hline \hline" _n;
file write resultsfile "\\[0.2cm]" _n;
file write resultsfile " Model  & Age 5-6  & Age 7-8  & Age 9-10 & Age 11-12    \\" _n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;

foreach i in 1 3 4 2 5 {;

local ind_j = 1;
forvalues j = 5(2)11{;

if `i' < 5{;
qui sum alpha`i'_age`j' in 1;
};
else{;
qui sum std_inv_age`j' in 1;
};

local column`ind_j':  di %6.3f r(mean) ;

if `i' < 5{;
qui sum alpha`i'_age`j',de;
};
else{;
qui sum std_inv_age`j',de;
};
local column`ind_j'_se: di %4.3f r(sd) ;
local column`ind_j'_lb: di %4.2f r(p5) ;
local column`ind_j'_ub: di %4.2f r(p95) ;

local ind_j = `ind_j' + 1;
};


if `i'==1{;
file write resultsfile "   Log Skills              & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "       at age 5    & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "          & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==3{;
file write resultsfile "   Log Mother              & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "        Cognitive Skills     & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "     & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==4{;
file write resultsfile "   Log Mother             & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "        Noncognitive Skills     & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "          & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==2{;
file write resultsfile "   Log Family & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "   Income     & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "        & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==5{;
file write resultsfile "   Standard Deviation & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "   Shocks     & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "       & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};
};

file write resultsfile "\hline \hline" _n;
file write resultsfile "\end{tabular}";
file close resultsfile;



************************************;
************************************;
*Technology;
************************************;
************************************;



file open resultsfile using "$paper_dir\est_tech.tex", write replace;
file write resultsfile "\begin{tabular}{lcccc}" _n;
file write resultsfile "\hline \hline" _n;
file write resultsfile "\\[0.2cm]" _n;
file write resultsfile " Model  & Age 5-6  & Age 7-8  & Age 9-10 & Age 11-12    \\" _n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;

forvalues i =1(1)5{;

local ind_j = 1;
forvalues j = 5(2)11{;

if `i' < 4{;
qui sum gamma`i'_age`j' in 1;
};
if `i' == 4{;
qui sum std_prod_age`j' in 1;
};
if `i' == 5{;
qui sum log_TFP_age`j' in 1;
};

local column`ind_j':  di %6.3f r(mean) ;




if `i' < 4{;
qui sum gamma`i'_age`j',de;
};
if `i' == 4{;
qui sum std_prod_age`j',de;
};
if `i' == 5{;
qui sum log_TFP_age`j',de;
};
local column`ind_j'_se: di %4.3f r(sd) ;
local column`ind_j'_lb: di %4.2f r(p5) ;
local column`ind_j'_ub: di %4.2f r(p95) ;

local ind_j = `ind_j' + 1;
};



if `i'==1{;
file write resultsfile "   Log Skills              & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "          & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "          & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==2{;
file write resultsfile "   Log Investments              & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "        & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "     & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==3{;
file write resultsfile "   Log Skills $\times$             & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "        Log Investments & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "          & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==4{;
file write resultsfile "   Standard Deviation & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "   Shocks      & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "        & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==5{;
file write resultsfile "   Log TFP & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "        & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "       & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

};



file write resultsfile "\hline \hline" _n;
file write resultsfile "\end{tabular}";
file close resultsfile;



************************************;
************************************;
*Adult Outcome Equation;
************************************;
************************************;


file open resultsfile using "$paper_dir\anchor_est.tex", write replace;
file write resultsfile "\begin{tabular}{lcc}" _n;
file write resultsfile "\hline \hline" _n;
file write resultsfile "\\[0.2cm]" _n;
file write resultsfile " Model  & Schooling  & Log Wage       \\" _n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;

forvalues i =0(1)2{;

forvalues j = 1(1)2{;

if `j'==1{;
qui sum alpha_anchor`i' in 1;
};
else{;
qui sum alpha_anchor`i'_wage in 1;
};

local column`j':  di %6.3f r(mean) ;
 
 
 
if `j'==1{;
qui sum alpha_anchor`i' ,de ;
};
else{;
qui sum alpha_anchor`i'_wage ,de ;
}; 
 
local column`j'_se: di %4.3f r(sd) ;
local column`j'_lb: di %4.2f r(p5) ;
local column`j'_ub: di %4.2f r(p95) ;
}; 
 


if `i'==0{;
file write resultsfile "  Constant & `column1' & `column2'    \\" _n;
file write resultsfile "        & (`column1_se') & (`column2_se')    \\" _n;
file write resultsfile "       & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub']   \\[0.3cm]" _n;
};

if `i'==1{;
file write resultsfile "  Log Children Skills & `column1' & `column2'    \\" _n;
file write resultsfile "  at age 13-14      & (`column1_se') & (`column2_se')    \\" _n;
file write resultsfile "       & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub']   \\[0.3cm]" _n;
};

if `i'==2{;
file write resultsfile "  Variance Shocks & `column1' & `column2'    \\" _n;
file write resultsfile "        & (`column1_se') & (`column2_se')    \\" _n;
file write resultsfile "       & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub']   \\[0.3cm]" _n;
};

};


file write resultsfile "\hline \hline" _n;
file write resultsfile "\end{tabular}";
file close resultsfile;





************************************;
************************************;
*Income Process Equation;
************************************;
************************************;




file open resultsfile using "$paper_dir\est_income.tex", write replace;
file write resultsfile "\begin{tabular}{lc}" _n;
file write resultsfile "\hline \hline" _n;
file write resultsfile "\\[0.2cm]" _n;

foreach param in inc_beta_const inc_beta_tm2 income_shock_std mean_income_age5{;

qui sum `param' in 1;
local column:  di %6.3f r(mean) ;
 
qui sum `param' ,de ;
 
local column_se: di %4.3f r(sd) ;
local column_lb: di %4.2f r(p5) ;
local column_ub: di %4.2f r(p95) ;

if "`param'"=="inc_beta_const"{;
file write resultsfile "  Constant & `column'      \\" _n;
file write resultsfile "        & (`column_se')   \\" _n;
file write resultsfile "       & [`column_lb',`column_ub']   \\[0.3cm]" _n;
};

if "`param'"=="inc_beta_tm2"{;
file write resultsfile "  Log Family Income t-1 & `column'      \\" _n;
file write resultsfile "        & (`column_se')   \\" _n;
file write resultsfile "       & [`column_lb',`column_ub']   \\[0.3cm]" _n;
};

if "`param'"=="income_shock_std"{;
file write resultsfile "  Standard Deviation Innovation & `column'      \\" _n;
file write resultsfile "        & (`column_se')   \\" _n;
file write resultsfile "       & [`column_lb',`column_ub']   \\[0.3cm]" _n;
};
 
if "`param'"=="mean_income_age5"{;
file write resultsfile "  Initial Mean Log-Income & `column'      \\" _n;
file write resultsfile "   at age 5-6     & (`column_se')   \\" _n;
file write resultsfile "       & [`column_lb',`column_ub']   \\[0.3cm]" _n;
}; 
 
};


file write resultsfile "\hline \hline" _n;
file write resultsfile "\end{tabular}";
file close resultsfile;





*******************************************************************************;
*******************************************************************************;
*Tables about Measurement Parameters;
*******************************************************************************;
*******************************************************************************;

preserve;
*upload estimated parameters;
cd "$scratch_dir";
use counter_ols0_restricted0 , clear;

********************;
*Children;
********************;


file open resultsfile using "$paper_dir\Sign_Noise_Children.tex", write replace;
file write resultsfile "\begin{tabular}{lcc}" _n;
file write resultsfile "\hline \hline" _n;
file write resultsfile "\\[0.2cm]" _n;
file write resultsfile "  Measures &  $\mu$ & $\lambda$  \\" _n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;

forvalues t = 5(2)13{;

if `t'==5{;
file write resultsfile "  Age 5-6 &   &   \\" _n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;
};

if `t'==7{;
file write resultsfile "  Age 7-8 &   &    \\" _n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;
};

if `t'==9{;
file write resultsfile "  Age 9-10 &   &    \\" _n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;
};

if `t'==11{;
file write resultsfile "  Age 11-12 &   &    \\" _n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;
};

if `t'==13{;
file write resultsfile "  Age 13-14 &   &    \\" _n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;
};


foreach x in  math  recog  comp {;

qui sum mu_`x'`t' in 1;
local column1:  di %6.3f r(mean) ;

qui sum lambda_`x'`t' in 1;
local column2:  di %6.3f r(mean) ;



if "`x'"=="math"{;
file write resultsfile "  PIAT Math  & `column1' & `column2'   \\" _n;
};

if "`x'"=="recog"{;
file write resultsfile "  PIAT Recognition  & `column1' & `column2'   \\" _n;
};

if "`x'"=="comp"{;
file write resultsfile "  PIAT Comprehensive  & `column1' & `column2'   \\[0.2cm] " _n;
};


};
};

file write resultsfile "\hline \hline" _n;
file write resultsfile "\end{tabular}";
file close resultsfile;


********************;
*Mothers;
********************;


file open resultsfile using "$paper_dir\Sign_Noise_Mother.tex", write replace;
file write resultsfile "\begin{tabular}{lcc}" _n;
file write resultsfile "\hline \hline" _n;
file write resultsfile "\\[0.2cm]" _n;
file write resultsfile "\multicolumn{3}{c}{Mother Cognitive Skills} \\"_n;
file write resultsfile "  Measures &  $\mu$ & $\lambda$ \\" _n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;


foreach x in asvab2 asvab3 asvab4 asvab5 asvab6 asvab8  {;

qui sum mu_`x' in 1;
local column1:  di %6.3f r(mean) ;

qui sum lambda_`x' in 1;
local column2:  di %6.3f r(mean) ;



if "`x'"=="asvab2"{;
file write resultsfile "  Mom's Arithmetic Reasoning  & `column1' & `column2'   \\[0.2cm]" _n;
};

if "`x'"=="asvab3"{;
file write resultsfile "  Mom's Word Knowledge & `column1' & `column2'   \\[0.2cm]" _n;
};

if "`x'"=="asvab4"{;
file write resultsfile " Mom's Paragraph Composition  & `column1' & `column2'  \\[0.2cm] " _n;
};

if "`x'"=="asvab5"{;
file write resultsfile "  Mom's Operations   & `column1' & `column2' \\[0.2cm] " _n;
};

if "`x'"=="asvab6"{;
file write resultsfile "  Mom's Coding Speed & `column1' & `column2' \\[0.2cm] " _n;
};

if "`x'"=="asvab8"{;
file write resultsfile "  Mom's Mathematical Knowledge & `column1' & `column2'   \\[0.2cm] " _n;
};


};




file write resultsfile "\\[0.2cm]" _n;
file write resultsfile "\multicolumn{3}{c}{Mother Non Cognitive Skills} \\"_n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;


foreach x in se1 se2 se3 se4 se5 se6 se8 se9 se10 rotter1 rotter2 rotter3 rotter4   {;

qui sum mu_`x' in 1;
local column1:  di %6.3f r(mean) ;

qui sum lambda_`x' in 1;
local column2:  di %6.3f r(mean) ;



if "`x'"=="se1"{;
file write resultsfile "  Mom's Self-Esteem: ''I am a person of worth''  & `column1' & `column2'   \\[0.2cm]" _n;
};

if "`x'"=="se2"{;
file write resultsfile "  Mom's Self-Esteem: ''I have good qualities'' & `column1' & `column2'   \\[0.2cm]" _n;
};

if "`x'"=="se3"{;
file write resultsfile " Mom's Self-Esteem: ''I am a failure''  & `column1' & `column2'   \\[0.2cm] " _n;
};

if "`x'"=="se4"{;
file write resultsfile "  Mom's Self-Esteem: ''I am as capable as others''   & `column1' & `column2'   \\[0.2cm] " _n;
};

if "`x'"=="se5"{;
file write resultsfile "  Mom's Self-Esteem: ''I have nothing to be proud of'' & `column1' & `column2'   \\[0.2cm] " _n;
};

if "`x'"=="se6"{;
file write resultsfile "  Mom's Self-Esteem: ''I have a positive attitude'' & `column1' & `column2'   \\[0.2cm] " _n;
};

if "`x'"=="se8"{;
file write resultsfile "  Mom's Self-Esteem: ''I wish I had more self-respect'' & `column1' & `column2'   \\[0.2cm] " _n;
};

if "`x'"=="se9"{;
file write resultsfile "  Mom's Self-Esteem: ''I feel useless at times'' & `column1' & `column2'   \\[0.2cm] " _n;
};

if "`x'"=="se10"{;
file write resultsfile "  Mom's Self-Esteem: ''I sometimes think I am no good'' & `column1' & `column2'   \\[0.2cm] " _n;
};


if "`x'"=="rotter1"{;
file write resultsfile "  Mom's Rotter Score: ''I have no control'' & `column1' & `column2'   \\[0.2cm] " _n;
};

if "`x'"=="rotter2"{;
file write resultsfile "  Mom's Rotter Score: ''I make no plans for the future'' & `column1' & `column2'   \\[0.2cm] " _n;
};


if "`x'"=="rotter3"{;
file write resultsfile "  Mom's Rotter Score: ''Luck is a big factor in life'' & `column1' & `column2'   \\[0.2cm] " _n;
};


if "`x'"=="rotter4"{;
file write resultsfile " Mom's Rotter Score: ''Luck plays big role in my life'' & `column1' & `column2'   \\[0.2cm] " _n;
};

};


file write resultsfile "\hline \hline" _n;
file write resultsfile "\end{tabular}";
file close resultsfile;

restore;









*******************************************************************************;
*******************************************************************************;
*Additional Robustness Analysis;
*******************************************************************************;
*******************************************************************************;


***********************************************************************;
*Technology with generalized estimator (averaging across measures);
***********************************************************************;

*upload estimated parameters;
cd "$scratch_dir";
use boot_collect_ols0_restricted0_new_generalized , clear;

sort boot_sample;

file open resultsfile using "$paper_dir\est_tech_generalized.tex", write replace;
file write resultsfile "\begin{tabular}{lcccc}" _n;
file write resultsfile "\hline \hline" _n;
file write resultsfile "\\[0.2cm]" _n;
file write resultsfile " Model  & Age 5-6  & Age 7-8  & Age 9-10 & Age 11-12    \\" _n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;

forvalues i =1(1)5{;

local ind_j = 1;
forvalues j = 5(2)11{;

if `i' < 4{;
qui sum gamma`i'_age`j' in 1;
};
if `i' == 4{;
qui sum std_prod_age`j' in 1;
};
if `i' == 5{;
qui sum log_TFP_age`j' in 1;
};

local column`ind_j':  di %6.3f r(mean) ;




if `i' < 4{;
qui sum gamma`i'_age`j',de;
};
if `i' == 4{;
qui sum std_prod_age`j',de;
};
if `i' == 5{;
qui sum log_TFP_age`j',de;
};
local column`ind_j'_se: di %4.3f r(sd) ;
local column`ind_j'_lb: di %4.2f r(p5) ;
local column`ind_j'_ub: di %4.2f r(p95) ;

local ind_j = `ind_j' + 1;
};



if `i'==1{;
file write resultsfile "   Log Skills              & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "          & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "          & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==2{;
file write resultsfile "   Log Investments              & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "        & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "     & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==3{;
file write resultsfile "   Log Skills $\times$             & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "        Log Investments & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "          & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==4{;
file write resultsfile "   Standard Deviation & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "   Shocks      & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "        & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==5{;
file write resultsfile "   Log TFP & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "        & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "       & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

};



file write resultsfile "\hline \hline" _n;
file write resultsfile "\end{tabular}";
file close resultsfile;




**********************************;
*Technology with CHS sample;
**********************************;



*upload estimated parameters;
cd "$scratch_dir";
use boot_collect_chs_sample , clear;

sort boot_sample;

file open resultsfile using "$paper_dir\est_tech_CHS.tex", write replace;
file write resultsfile "\begin{tabular}{lcccc}" _n;
file write resultsfile "\hline \hline" _n;
file write resultsfile "\\[0.2cm]" _n;
file write resultsfile " Model  & Age 5-6  & Age 7-8  & Age 9-10 & Age 11-12    \\" _n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;

forvalues i =1(1)5{;

local ind_j = 1;
forvalues j = 5(2)11{;

if `i' < 4{;
qui sum gamma`i'_age`j' in 1;
};
if `i' == 4{;
qui sum std_prod_age`j' in 1;
};
if `i' == 5{;
qui sum log_TFP_age`j' in 1;
};

local column`ind_j':  di %6.3f r(mean) ;




if `i' < 4{;
qui sum gamma`i'_age`j',de;
};
if `i' == 4{;
qui sum std_prod_age`j',de;
};
if `i' == 5{;
qui sum log_TFP_age`j',de;
};
local column`ind_j'_se: di %4.3f r(sd) ;
local column`ind_j'_lb: di %4.2f r(p5) ;
local column`ind_j'_ub: di %4.2f r(p95) ;

local ind_j = `ind_j' + 1;
};



if `i'==1{;
file write resultsfile "   Log Skills              & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "          & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "          & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==2{;
file write resultsfile "   Log Investments              & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "        & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "     & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==3{;
file write resultsfile "   Log Skills $\times$             & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "        Log Investments & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "          & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==4{;
file write resultsfile "   Standard Deviation & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "   Shocks      & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "        & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==5{;
file write resultsfile "   Log TFP & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "        & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "       & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

};



file write resultsfile "\hline \hline" _n;
file write resultsfile "\end{tabular}";
file close resultsfile;



**********************************;
*Technology with additional controls;
**********************************;


*upload estimated parameters;
cd "$scratch_dir";
use boot_collect_new_controls , clear;

sort boot_sample;

file open resultsfile using "$paper_dir\est_tech_new_controls.tex", write replace;
file write resultsfile "\begin{tabular}{lcccc}" _n;
file write resultsfile "\hline \hline" _n;
file write resultsfile "\\[0.2cm]" _n;
file write resultsfile " Model  & Age 5-6  & Age 7-8  & Age 9-10 & Age 11-12    \\" _n;
file write resultsfile "\hline" _n;
file write resultsfile "\\[0.2cm]" _n;

forvalues i =1(1)5{;

local ind_j = 1;
forvalues j = 5(2)11{;

if `i' < 4{;
qui sum gamma`i'_age`j' in 1;
};
if `i' == 4{;
qui sum std_prod_age`j' in 1;
};
if `i' == 5{;
qui sum log_TFP_age`j' in 1;
};

local column`ind_j':  di %6.3f r(mean) ;




if `i' < 4{;
qui sum gamma`i'_age`j',de;
};
if `i' == 4{;
qui sum std_prod_age`j',de;
};
if `i' == 5{;
qui sum log_TFP_age`j',de;
};
local column`ind_j'_se: di %4.3f r(sd) ;
local column`ind_j'_lb: di %4.2f r(p5) ;
local column`ind_j'_ub: di %4.2f r(p95) ;

local ind_j = `ind_j' + 1;
};



if `i'==1{;
file write resultsfile "   Log Skills              & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "          & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "          & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==2{;
file write resultsfile "   Log Investments              & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "        & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "     & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==3{;
file write resultsfile "   Log Skills $\times$             & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "        Log Investments & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "          & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==4{;
file write resultsfile "   Standard Deviation & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "   Shocks      & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "        & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

if `i'==5{;
file write resultsfile "   Log TFP & `column1' & `column2' & `column3' & `column4'  \\" _n;
file write resultsfile "        & (`column1_se') & (`column2_se') & (`column3_se') & (`column4_se')  \\" _n;
file write resultsfile "       & [`column1_lb',`column1_ub'] & [`column2_lb',`column2_ub'] & [`column3_lb',`column3_ub'] & [`column4_lb',`column4_ub']  \\[0.3cm]" _n;
};

};



file write resultsfile "\hline \hline" _n;
file write resultsfile "\end{tabular}";
file close resultsfile;




